package com.autumn.sms.service.core.impl;

import org.springframework.stereotype.Service;

import com.autumn.sms.SmsEventData;
import com.autumn.sms.service.consts.ServiceConsts.Platform;
import com.autumn.sms.service.vo.PlatformTemplateValue;
import com.autumn.util.ExceptionUtils;

/**
 * 
 * @author 老码农
 *
 *         2018-01-12 19:12:53
 */
@Service(Platform.BEAN_NAME_ALIYUN)
public class AliYunSmsServiceImpl extends AbstractSmsPlatformService {

	@Override
	public void send(PlatformTemplateValue platformTemplate, SmsEventData eventData) {
		ExceptionUtils.throwValidationException("暂不支持。");

		/*String key = this.checkConfigInfo(platformTemplate, "key", String.class, true);
		String url = this.checkConfigInfo(platformTemplate, "url", String.class, true);
		String app_secret = this.checkConfigInfo(platformTemplate, "app_secret", String.class, true);
		String sign_name = platformTemplate.getSignName();
		if (sign_name == null) {
			sign_name = "";
		}
		Map<String, String> reqMap = platformTemplate.generatePlatformParameter(eventData.getParams());

		Map<String, String> querys = new HashMap<String, String>(16);
		querys.put("SignName", sign_name);
		querys.put("TemplateCode", platformTemplate.getTemplateCode());
		querys.put("RecNum", eventData.getMobilePhone());
		querys.put("ParamString", JSON.toJSONString(reqMap));

		Request request = new Request(Method.GET, url, "/singleSendSms", key, app_secret, 1000 * 30);
		request.setQuerys(querys);

		Map<String, String> bodymap = new HashMap<String, String>(16);
		Response response = null;
		try {
			response = Client.execute(request);
		} catch (Exception e) {
			throw new NetworkException(e.getMessage(), e);
		} // 根据实际业务需要，调整对response的处理
		if (null == response) {
			throw new NetworkException("无响应结果");
		} else if (200 != response.getStatusCode()) {
			throw new NetworkException("响应状态:" + response.getStatusCode());
		} else {
			bodymap = readResponseBodyContent(response.getBody());
			String errorMessage = bodymap.get("errorMessage");
			if (null != errorMessage) {
				throw new NetworkException(errorMessage);
			}
		}*/

	}

	/*
	 * private Map<String, String> readResponseBodyContent(String body) {
	 * Map<String, String> map = new HashMap<String, String>(16); JSONObject
	 * jsonObject = JSON.parseObject(body); if (null != jsonObject) { for
	 * (Entry<String, Object> entry : jsonObject.entrySet()) {
	 * map.put(entry.getKey(), entry.getValue().toString()); } } if
	 * ("false".equals(map.get("success"))) { map.put("errorMessage",
	 * map.get("message")); } return map; }
	 */

}
